import {observable, action} from "mobx";
import request from "../utils/request";
import * as api from "../api/api";
import {LoadHoc, loading} from '../hoc/loadHoc';

export default class HomeStore extends LoadHoc {
  /**
   * 实名认证
   */
  @loading @action
  async creditCardActualVerify(params: {
    form: {
      idCardNo: string,
      cardNo: string,
      realName: string,
      reservePhone: string,
      smsCod: string
    },
    callback?: (res) => void;
  }) {
    const {form, callback} = params;
    const res = await request(api.AppcreditCardApiFetchParamCreactor.appcreditCardActualVerifyAsync({
      form
    }));
    callback && callback(res);
  }

  /**
   * 添加信用卡
   */
  @loading @action
  async creditCardSaveCard(params: {
    form: {
      cardNo: string,
      cardType: number,
      realName: string,
      idCardNo: string,
      reservePhone: string,
      cardCVV2: string,
      validity: string,
      billDay: number,
      repaymentDate: number,
    },
    callback?: (res) => void;
  }) {
    const {form, callback} = params;
    const res = await request(api.AppcreditCardApiFetchParamCreactor.appcreditCardSaveCardAsync({
      form
    }));
    callback && callback(res);
  }

  /**
   * 删除信用卡列表
   */
  @loading @action
  async creditCardDeleteCard(params: {
    id: number,
    callback?: (res) => void;
  }) {
    const {id, callback} = params;
    const res = await request(api.AppcreditCardApiFetchParamCreactor.appcreditCardDeleteCardAsync({
      form: {
        id
      }
    }));
    callback && callback(res);
  }

  /**
   * 获取信用卡列表
   */
  @loading @action
  async creditCardGetCardList(params: {
    cardType: number,
    pageIndex: number,
    pageSize: number,
    callback?: (res: api.SingleUserMallCreditCardVOCardListVO) => void;
  }) {
    const {cardType, pageIndex, pageSize, callback} = params;
    const res = await request(api.AppcreditCardApiFetchParamCreactor.appcreditCardGetCardListAsync({
      formCardType: cardType,
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize,
    }));
    callback && callback(res);
  }
}
